package com.gz.rocketmq.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

public class SyncProducer {
    public static void main(String[] args) throws InterruptedException, RemotingException, MQClientException, MQBrokerException, UnsupportedEncodingException {
        // 实例化消息生产者Producer
        DefaultMQProducer producer = new DefaultMQProducer("rocketmq01");
        try {
           //连接NameServer
           producer.setNamesrvAddr("192.168.36.128:9876");
           producer.start();
           for (int i = 0; i < 10; i++) {
               Message message = new Message();
               message.setTopic("topic01");
               message.setTags("tag01");
               message.setBody((i + "-Hello01").getBytes());
               SendResult result = producer.send(message,10000);
               System.out.println(result);
           }
       }finally {
           producer.shutdown();
       }

    }
}
